/**
 * Created with IntelliJ IDEA.
 * Description:寻找数组的中心下标
 * User: bjc
 * Date: 2025-11-18
 * Time: 19:20
 */
public class Test03_pivotIndex {
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] dp_left = new int[n];
        int[] dp_right = new int[n];
        for (int i = 1; i < n; i++) {
            dp_left[i] = nums[i - 1] + dp_left[i - 1];
        }
        for (int i = n - 2; i >= 0; i--) {
            dp_right[i] = dp_right[i + 1] + nums[i + 1];
        }
        for (int i = 0; i < n; i++) {
            if (dp_left[i] == dp_right[i])
                return i;
        }
        return -1;
    }
}
